﻿//-----------------------------------------------------------------------
// <copyright file="EngineOperation.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the EngineOperation class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.EngineOperation
{
    using Tuples;
    using Tuple = Tuples.Tuple;

    /// <summary>
    /// Base class for implementing an engine operation.
    /// </summary>
    /// <typeparam name="T">The type of data on which the operation acts.</typeparam>
    internal abstract class EngineOperation<T> : IEngineOperation
    {
        /// <summary>
        /// The current tuple store session.
        /// </summary>
        protected TupleStoreSession session;

        /// <summary>
        /// The data on which the operation acts.
        /// </summary>
        protected T data;

        #region IEngineOperation Members

        /// <summary>
        /// Performs the engine operation.
        /// </summary>
        /// <param name="facts">Collection of facts on which the operation may optionally act.</param>
        /// <returns>Indicates if the engine should start a new match-resolve-do cycle.</returns>
        public abstract bool Perform(ref object[] facts);

        #endregion

        /// <summary>
        /// Obtains a Entity Tuple for the given fact.
        /// </summary>
        /// <param name="fact">A fact fro which an Entity Tuple is required.</param>
        /// <returns>An Entity Tuple.</returns>
        protected Tuple GetEntityTuple(object fact)
        {
            // Dump
            System.Diagnostics.Debug.WriteLine(">> assert f" + "    " + fact.ToString());

            return this.session.GetEntityTuple(fact);
        }
    }
}
